<template>
  <a-card class="j-address-list-right-card-box" :loading="cardLoading" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form-model layout="inline" :model="queryParam">
        <a-row :gutter="10">
          <a-col :md="17" :sm="12">
            <a-form-model-item label="" prop="realname" style="margin-left: 8px">
              <a-input placeholder="请输入账套名称" v-model="queryParam.accName"></a-input>
            </a-form-model-item>
          </a-col>

          <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
            <a-col :md="6" :sm="24">
              <a-button type="primary" @click="searchQuery" icon="search" style="margin-left: 18px">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">清除条件</a-button>
            </a-col>
          </span>
        </a-row>
      </a-form-model>
    </div>

    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="userId"
      :pagination="false"
      :columns="columns"
      :dataSource="dataSource"
      :loading="loading"
      :row-selection="rowSelection"
    >
    </a-table>
  </a-card>
</template>

<script>
import { getAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'AddressListRight',
  mixins: [JeecgListMixin],
  components: {},
  props: ['value', 'checkStatus'],
  data() {
    return {
      description: '用户信息',
      cardLoading: true,
      positionInfo: {},
      queryParam: {
        // TODO 账套id -----
        accName: ''
        // TODO 账套 -----
        // isChildren:''
      },
      superParam: {
        unitId: '',
      },
      reportIds: [],
      columns: [
        {
          title: '序号',
          key: 'rowIndex',
          dataIndex: '',
          width: 60,
          align: 'center',
          customRender: (t, r, i) => parseInt(i) + 1
        },
        {
          title: '账套编号',
          align: 'center',
          width: '30%',
          dataIndex: 'accCode'
        },
        {
          title: '账套名称',
          align: 'center',
          dataIndex: 'accName'
        }
      ],
      url: {
        // list: '/sjzxzy/sjZxzyElectronicBook/queryElectronicBookInfo'
        list: '/sjyzzx/sjZxzyAccInfo/queryAccInfo',
        depart:'/sys/sysDepart/queryDeptChange'
      },
      disableMixinCreated: true
    }
  },
  watch: {
    value: {
      immediate: true,
      handler(orgCode) {
        // TODO 账套id -----
        this.getDeptChange(orgCode);
        this.dataSource = []
      }
    },
    checkStatus: {
      immediate: true,
      handler(isChildren) {
        // TODO 账套 -----
        // this.queryParam.isChildren = isChildren
        this.dataSource = []
        this.loadData(1)
      }
    }
  },
  created() {},
  computed: {
    rowSelection() {
      return {
        onChange: (selectedRowKeys, selectedRows) => {
          this.reportIds = []
          console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows)
          selectedRows.map(item => {
            // TODO 账套～～～
            console.log(item, 'item~~~')
            this.reportIds.push({ accCode: item.accCode, accName: item.accName, id: item.id, unitId: item.unitId })
          })
          this.$emit('onSelect', this.reportIds)
        }
      }
    }
  },
  methods: {
    loadData(pageNum) {
      this.loading = true
      if (pageNum === 1) {
        this.ipagination.current = 1
      }
      // update-begin- --- author:wangshuai ------ date:20200102 ---- for:传过来的部门编码为空全查
      getAction(this.url.list, {
        ...this.getQueryParams()
      })
        .then(res => {
          if (res.success) {
            this.dataSource = res.result
            // this.ipagination.total = res.result.total
          }
        })
        .finally(() => {
          this.loading = false
          this.cardLoading = false
        })
      // update-end- --- author:wangshuai ------ date:20200102 ---- for:传过来的部门编码为空全查
    },

    searchQuery() {
      this.loadData(1, this.value)
    },
    searchReset() {
      this.queryParam = {}
      this.loadData(1, this.value)
    },
    // handleTableChange(pagination, filters, sorter) {
    //   if (Object.keys(sorter).length > 0) {
    //     this.isorter.column = sorter.field
    //     this.isorter.order = 'ascend' === sorter.order ? 'asc' : 'desc'
    //   }
    //   this.ipagination = pagination
    //   this.loadData(null, this.value)
    // }
    // 获取unitId
    getDeptChange(id) {
      getAction(this.url.depart, { id }).then((res) => {
        if (res.success) {
          this.superParam.unitId = res.result
        } else {
          this.superParam.unitId = ''
        }
        this.loadData(1)
      })
    }
  }
}
</script>
<style>
.j-address-list-right-card-box .ant-table-placeholder {
  min-height: 46px;
}
</style>
<style scoped>
.j-address-list-right-card-box {
  height: 100%;
  min-height: 300px;
}
</style>